#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
int main()
{
    //close(1);
    //int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //int fd = open("log.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    int fd = open("log.txt", O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        exit(errno);
    }
    //dup2(fd, 1);
    //printf("fd : %d\n", fd);
    //fprintf(stdout, "fd : %d\n", fd);
    //const char* str = "hello world\n";
    //write(1, str, strlen(str));
    //fflush(stdout);
    dup2(fd, 0);
    
    char line[64] = {0};

    while(1)
    {
        printf("> ");
        if(fgets(line, sizeof line, stdin) == NULL) break;
        printf("%s", line);
    }
    
    close(fd);
    return 0;
}
